package com.zhan.signalling.data.listener;

import com.corundumstudio.socketio.AckRequest;
import com.corundumstudio.socketio.SocketIOClient;
import com.corundumstudio.socketio.listener.DataListener;
import com.zhan.signalling.check.AccoutPermissionCheck;
import com.zhan.signalling.commons.Constants;
import com.zhan.signalling.commons.SocketEvent;
import com.zhan.signalling.message.Message;
import com.zhan.signalling.message.Result;
import com.zhan.signalling.util.RedisUtil;

/**
 * 禁言
 * @author knight
 *
 */
public class ForbiddenWordListener implements DataListener<Message> {

	public void onData(SocketIOClient client, Message data, AckRequest ackSender) throws Exception {
		
		// 校验权限
		AccoutPermissionCheck.check(client, SocketEvent.FORBIDDEN_WORD_EVENT);
		
		String groupId = client.get(Constants.GROUP_KEY);
		String platform = client.getNamespace().getName();
		String token = data.getTo();
		RedisUtil.addForbiddenWord(platform + ":" + groupId, token);
		ackSender.sendAckData(new Result("Forbidden Word success", Constants.SUCCESS));
		client.sendEvent(SocketEvent.FORBIDDEN_WORD_EVENT, new Result("Forbidden Word success", Constants.SUCCESS));
		
	}

}
